#include "ds18b20.h"

#include <stdio.h>
#include <string.h>


static void dummy_delay_ms(volatile unsigned int t) {
	while (t --);
}


int DS18B20_example(void) {
	DS18B20_REG_T ds18b20;
	int temp_hex;
	
	/* open device */
	if(DS_open(&ds18b20) != 0) {
		return -1;
	}
	
	/* start tempreture convert */
	if(DS_start_con(&ds18b20) != 0) {
	 	DS_close();
		return -1;
	}
	
	/* ds18b20.con_time is in US */
	dummy_delay_ms(ds18b20.con_time * 1000);
	
	/* read tempreture */
	temp_hex = DS_read_temp(&ds18b20);
	if(temp_hex == -1) {
	 	DS_close();
		return -1;
	}
	
	/* close device */
	DS_close();
 	return 0;
}
